home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / BaseClasses / transip.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  8.4 KB  |  247 lines

  1. //------------------------------------------------------------------------------
  2. // File: TransIP.h
  3. //
  4. // Desc: DirectShow base classes - defines classes from which simple
  5. //       Transform-In-Place filters may be derived.
  6. //
  7. // Copyright (c) 1992-2001 Microsoft Corporation.  All rights reserved.
  8. //------------------------------------------------------------------------------
  9.  
  10.  
  11. //
  12. // The difference between this and Transfrm.h is that Transfrm copies the data.
  13. //
  14. // It assumes the filter has one input and one output stream, and has no
  15. // interest in memory management, interface negotiation or anything else.
  16. //
  17. // Derive your class from this, and supply Transform and the media type/format
  18. // negotiation functions. Implement that class, compile and link and
  19. // you're done.
  20.  
  21.  
  22. #ifndef __TRANSIP__
  23. #define __TRANSIP__
  24.  
  25. // ======================================================================
  26. // This is the com object that represents a simple transform filter. It
  27. // supports IBaseFilter, IMediaFilter and two pins through nested interfaces
  28. // ======================================================================
  29.  
  30. class CTransInPlaceFilter;
  31.  
  32. // Several of the pin functions call filter functions to do the work,
  33. // so you can often use the pin classes unaltered, just overriding the
  34. // functions in CTransInPlaceFilter.  If that's not enough and you want
  35. // to derive your own pin class, override GetPin in the filter to supply
  36. // your own pin classes to the filter.
  37.  
  38. // ==================================================
  39. // Implements the input pin
  40. // ==================================================
  41.  
  42. class CTransInPlaceInputPin : public CTransformInputPin
  43. {
  44.  
  45. protected:
  46.     CTransInPlaceFilter * const m_pTIPFilter;    // our filter
  47.     BOOL                 m_bReadOnly;    // incoming stream is read only
  48.  
  49. public:
  50.  
  51.     CTransInPlaceInputPin(
  52.         TCHAR               *pObjectName,
  53.         CTransInPlaceFilter *pFilter,
  54.         HRESULT             *phr,
  55.         LPCWSTR              pName);
  56.  
  57.     // --- IMemInputPin -----
  58.  
  59.     // Provide an enumerator for media types by getting one from downstream
  60.     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
  61.  
  62.     // Say whether media type is acceptable.
  63.     HRESULT CheckMediaType(const CMediaType* pmt);
  64.  
  65.     // Return our upstream allocator
  66.     STDMETHODIMP GetAllocator(IMemAllocator ** ppAllocator);
  67.  
  68.     // get told which allocator the upstream output pin is actually
  69.     // going to use.
  70.     STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator,
  71.                                  BOOL bReadOnly);
  72.  
  73.     // Allow the filter to see what allocator we have
  74.     // N.B. This does NOT AddRef
  75.     IMemAllocator * PeekAllocator() const
  76.         {  return m_pAllocator; }
  77.  
  78.     // Pass this on downstream if it ever gets called.
  79.     STDMETHODIMP
  80.     CTransInPlaceInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps);
  81.  
  82.     inline const BOOL ReadOnly() { return m_bReadOnly ; }
  83.  
  84. };  // CTransInPlaceInputPin
  85.  
  86. // ==================================================
  87. // Implements the output pin
  88. // ==================================================
  89.  
  90. class CTransInPlaceOutputPin : public CTransformOutputPin
  91. {
  92.  
  93. protected:
  94.     // m_pFilter points to our CBaseFilter
  95.     CTransInPlaceFilter * const m_pTIPFilter;
  96.  
  97. public:
  98.  
  99.     CTransInPlaceOutputPin(
  100.         TCHAR               *pObjectName,
  101.         CTransInPlaceFilter *pFilter,
  102.         HRESULT             *phr,
  103.         LPCWSTR              pName);
  104.  
  105.  
  106.     // --- CBaseOutputPin ------------
  107.  
  108.     // negotiate the allocator and its buffer size/count
  109.     // Insists on using our own allocator.  (Actually the one upstream of us).
  110.     // We don't override this - instead we just agree the default
  111.     // then let the upstream filter decide for itself on reconnect
  112.     // virtual HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc);
  113.  
  114.     // Provide a media type enumerator.  Get it from upstream.
  115.     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
  116.  
  117.     // Say whether media type is acceptable.
  118.     HRESULT CheckMediaType(const CMediaType* pmt);
  119.  
  120.     //  This just saves the allocator being used on the output pin
  121.     //  Also called by input pin's GetAllocator()
  122.     void SetAllocator(IMemAllocator * pAllocator);
  123.  
  124.     IMemInputPin * ConnectedIMemInputPin()
  125.         { return m_pInputPin; }
  126.  
  127.     // Allow the filter to see what allocator we have
  128.     // N.B. This does NOT AddRef
  129.     IMemAllocator * PeekAllocator() const
  130.         {  return m_pAllocator; }
  131. };  // CTransInPlaceOutputPin
  132.  
  133.  
  134. class AM_NOVTABLE CTransInPlaceFilter : public CTransformFilter
  135. {
  136.  
  137. public:
  138.  
  139.     // map getpin/getpincount for base enum of pins to owner
  140.     // override this to return more specialised pin objects
  141.  
  142.     virtual CBasePin *GetPin(int n);
  143.  
  144. public:
  145.  
  146.     //  Set bModifiesData == false if your derived filter does
  147.     //  not modify the data samples (for instance it's just copying
  148.     //  them somewhere else or looking at the timestamps).
  149.  
  150.     CTransInPlaceFilter(TCHAR *, LPUNKNOWN, REFCLSID clsid, HRESULT *,
  151.                         bool bModifiesData = true);
  152. #ifdef UNICODE
  153.     CTransInPlaceFilter(CHAR *, LPUNKNOWN, REFCLSID clsid, HRESULT *,
  154.                         bool bModifiesData = true);
  155. #endif
  156.     // The following are defined to avoid undefined pure virtuals.
  157.     // Even if they are never called, they will give linkage warnings/errors
  158.  
  159.     // We override EnumMediaTypes to bypass the transform class enumerator
  160.     // which would otherwise call this.
  161.     HRESULT GetMediaType(int iPosition, CMediaType *pMediaType)
  162.         {   DbgBreak("CTransInPlaceFilter::GetMediaType should never be called");
  163.             return E_UNEXPECTED;
  164.         }
  165.  
  166.     // This is called when we actually have to provide out own allocator.
  167.     HRESULT DecideBufferSize(IMemAllocator*, ALLOCATOR_PROPERTIES *);
  168.  
  169.     // The functions which call this in CTransform are overridden in this
  170.     // class to call CheckInputType with the assumption that the type
  171.     // does not change.  In Debug builds some calls will be made and
  172.     // we just ensure that they do not assert.
  173.     HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
  174.     {
  175.         return S_OK;
  176.     };
  177.  
  178.  
  179.     // =================================================================
  180.     // ----- You may want to override this -----------------------------
  181.     // =================================================================
  182.  
  183.     HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin);
  184.  
  185.     // chance to customize the transform process
  186.     virtual HRESULT Receive(IMediaSample *pSample);
  187.  
  188.     // =================================================================
  189.     // ----- You MUST override these -----------------------------------
  190.     // =================================================================
  191.  
  192.     virtual HRESULT Transform(IMediaSample *pSample) PURE;
  193.  
  194.     // this goes in the factory template table to create new instances
  195.     // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
  196.  
  197.  
  198. #ifdef PERF
  199.     // Override to register performance measurement with a less generic string
  200.     // You should do this to avoid confusion with other filters
  201.     virtual void RegisterPerfId()
  202.          {m_idTransInPlace = MSR_REGISTER(TEXT("TransInPlace"));}
  203. #endif // PERF
  204.  
  205.  
  206. // implementation details
  207.  
  208. protected:
  209.  
  210.     IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource);
  211.  
  212. #ifdef PERF
  213.     int m_idTransInPlace;                 // performance measuring id
  214. #endif // PERF
  215.     bool  m_bModifiesData;                // Does this filter change the data?
  216.  
  217.     // these hold our input and output pins
  218.  
  219.     friend class CTransInPlaceInputPin;
  220.     friend class CTransInPlaceOutputPin;
  221.  
  222.     CTransInPlaceInputPin  *InputPin() const
  223.     {
  224.         return (CTransInPlaceInputPin *)m_pInput;
  225.     };
  226.     CTransInPlaceOutputPin *OutputPin() const
  227.     {
  228.         return (CTransInPlaceOutputPin *)m_pOutput;
  229.     };
  230.  
  231.     //  Helper to see if the input and output types match
  232.     BOOL TypesMatch()
  233.     {
  234.         return InputPin()->CurrentMediaType() ==
  235.                OutputPin()->CurrentMediaType();
  236.     }
  237.  
  238.     //  Are the input and output allocators different?
  239.     BOOL UsingDifferentAllocators() const
  240.     {
  241.         return InputPin()->PeekAllocator() != OutputPin()->PeekAllocator();
  242.     }
  243. }; // CTransInPlaceFilter
  244.  
  245. #endif /* __TRANSIP__ */
  246.  
  247.